/**
 * Created by Administrator on 2018/11/14.
 */

$(function(){
	var reg = /^1(3|4|5|7|8)\d{9}$/;
    /* 验证码 */
    $("#registerBtn").on('click',function(){
        var _this = $(this);
        var mobile = $("#registerCall").val();
        if(!reg.test(mobile)){
        	sstb.dialog('手机号码格式错误');
        	return false;
        }
        _this.attr('disabled',true);
        $.get("/user/fogetcode",{mobile: mobile},function(result){
   		 if(result.code == 0){
   			djs(_this);
   		 }else{
   			 _this.attr('disabled',false);
   			sstb.dialog(result.msg);
   		 }
        });
    });
    
    $("#SignInBtn").on('click',function(){
    	var mobile = $("#registerCall").val();
    	var code = $("#code").val();
    	var newpwd = $("#newpwd").val();
    	var newok = $("#newok").val();
    	if(newpwd != newok){
    		sstb.dialog('输入的密码不一致');
    		return false;
    	}
    	$.post("/forget/password", {code: code,newPwd: newpwd,mobile: mobile,type: 'pc'},function(result){
    		if(result.code == 0){
    			window.location.href='/signup';
    		}else{
    			sstb.dialog(result.msg);
    		}
    	})
    })
    
    
})

function djs(value){
        var time = 60;
        var timer = setInterval(func,1000);
        function func(){
            time--;
            value.val(time + "s后重新获取");
            if(time == 0){
                value.val("重新获取");
                clearInterval(timer);
                value.attr('disabled',false);
            }
        }
}
